// Open a single window
var window = Ti.UI.createWindow({
	backgroundColor:'black'
});

// Obtain game module
var quicktigame2d = require('com.googlecode.quicktigame2d');

// Create view for your game.
var game = quicktigame2d.createGameView();

if(Titanium.Platform.osname === 'android') {
	// On Android platform it looks like the LANDSCAPE_RIGHT never work
	// when orientation are locked to portrait by system settings.
	// (Tested on Samsung Galaxy Tab & HTC EVO 3D)
	window.orientationModes = [Ti.UI.LANDSCAPE_LEFT];
	game.orientation = Ti.UI.LANDSCAPE_LEFT;
} else {
	// On iPhone, iPod touch and iPad we prefer to use LANDSCAPE_RIGHT
	window.orientationModes = [Ti.UI.LANDSCAPE_RIGHT];
	game.orientation = Ti.UI.LANDSCAPE_RIGHT;
}

// Frame rate can be changed (fps can not be changed after the game is loaded)
game.fps = 30;

// set initial background color to black
game.color(0, 0, 0);

// Include scenes
Ti.include("debug.js");
Ti.include('loadingScene.js');
Ti.include('titleScene.js');
Ti.include('howtoScene.js');
Ti.include('creditScene.js');
Ti.include('mainLoadingScene.js');
Ti.include('mainScene.js');

// Titanium returns non-retina values on Retina devices for the view size so we have to calculate the scale.
var WINDOW_SCALE_FACTOR_X = 1;
var WINDOW_SCALE_FACTOR_Y = 1;

game.addEventListener('onload', function(e) {
    
	// set screen size for your game (non-retina size)
	var screenScale = game.height / 320;
	game.screen = {width:game.width / screenScale, height:game.height / screenScale};
  
    Ti.API.info("view size: " + game.width + "x" + game.height);
    Ti.API.info("game screen size: " + game.screen.width + "x" + game.screen.height);

 	// If no screen parameter is given, on Retina device this scale will be 2.
	// Titanium returns non-retina values even on Retina devices for the view size.
    // Now we already update the screen size to fit with non-retina size like below, this scale will be 1.
    // game.screen = {width:480, height:320};
    WINDOW_SCALE_FACTOR_X = game.screen.width  / game.width;
    WINDOW_SCALE_FACTOR_Y = game.screen.height / game.height;

    // Initialize loading scene    
    LoadingScene.init();

    game.pushScene(LoadingScene.scene);
    game.start();
});

//Ti.App.addEventListener('pause', function(e) {
//
//});

//Ti.App.addEventListener('resume', function(e) {
//    
//});

// Add your game view
window.add(game);
window.open({fullscreen:true, navBarHidden:true});
